function compareOptionValues(a, b) 
{ var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;}

function compareOptionText(a, b) { 
/*  var sA = parseInt(a.text, 32);  
  var sB = parseInt(b.text, 32);
	
  if(isNaN(sA))
	return -1;
  else if(isNaN(sB))
	return 1;
  else
	return sA - sB;
  */

  return a.text.localeCompare(b.text);
}

function onAction (sender, value){
	sender.value = value;
}

function CopySelected(destList,selText,separatorString){
  selText.value = "";
  for( len = 0; len < destList.options.length; len++ ) {
       selText.value = selText.value + separatorString + destList.options[len].value;
  }
  selText.value=selText.value.substr(separatorString.length);
}

function CopySelectedText(destList,selText, separatorString){
  selText.value = "";
  for( len = 0; len < destList.options.length; len++ ) {
       selText.value = selText.value + separatorString + "'" + destList.options[len].value + "'";
  }
  selText.value=selText.value.substr(1);
}

function moveDualList( srcList, destList, moveAll, selText ) {
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {    return;  }
  newDestList = new Array( destList.options.length );

  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) {
    if ( destList.options[ len ] != null ){
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
      }
  }
  for( var i = 0; i < srcList.options.length; i++ ) { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )    {
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
       }
  }
  newDestList.sort(compareOptionText);

  for ( var j = 0; j < newDestList.length; j++ ) {
    if ( newDestList[ j ] != null ){
      destList.options[ j ] = newDestList[ j ];}
  }

  for( var i = srcList.options.length - 1; i >= 0; i-- ) { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) ){
       srcList.options[i]       = null;}
  }
  
  
}

function changeDisplay( arrayControls, img ){
	var row;
	var cell;
	for(var i=0; i<arrayControls.length; i++){
		if(img.name == 'hide' ){
			document.getElementById(arrayControls[i]).style.display = "none";		
		}else{
			document.getElementById(arrayControls[i]).style.display = "";
			row = document.getElementById(arrayControls[i]);
			cell = row.firstChild;
			//img con mas, debo cambiar a menos
			if(cell != null){
				if(cell.childNodes.length > 0 && cell.childNodes.item(0)!=null){
					var nameImg = cell.childNodes.item(0).attributes.getNamedItem('name');
					if( nameImg != null){
						if( nameImg.nodeValue == 'show'){
							cell.childNodes.item(0).attributes.getNamedItem('name').nodeValue = 'hide';
							cell.childNodes.item(0).attributes.getNamedItem('src').nodeValue = '/webctrl_client/1_0/treeimages/minus.gif';
						}
					}
				}
			}
		}
	} 

	if(img.name == 'hide'){
		img.src = "/webctrl_client/1_0/treeimages/plus.gif";
		img.name = "show";
	}else{
		img.src = "/webctrl_client/1_0/treeimages/minus.gif";
		img.name = "hide";
	}
	
}


function showBar( trackingID ){

	var aDivs = document.getElementsByTagName("div");
		
	for(var i=0; i< aDivs.length; i++){
		
		var nodeDiv = aDivs.item(i).attributes.getNamedItem("trackingID");
		var nodeTracking = aDivs.item(i).attributes.getNamedItem("tracking");
		if(nodeDiv != null){
			
			if( aDivs.item(i).attributes.getNamedItem("trackingID").nodeValue == trackingID ){
				
				if( document.getElementById(aDivs.item(i).attributes.getNamedItem("id").nodeValue).style.display != "none")
					document.getElementById(aDivs.item(i).attributes.getNamedItem("id").nodeValue).style.display="none";
				else
					document.getElementById(aDivs.item(i).attributes.getNamedItem("id").nodeValue).style.display="";
			
			}else{
				if(nodeTracking != null){
					if( nodeTracking.nodeValue == 'false' )
						document.getElementById(aDivs.item(i).attributes.getNamedItem("id").nodeValue).style.display="";
					else
						document.getElementById(aDivs.item(i).attributes.getNamedItem("id").nodeValue).style.display="none";
				}
			}
		}
	}
}

function toolTip( arrayControls, event ){
	for(var i=0; i<arrayControls.length; i++){
	
		if( document.getElementById(arrayControls[i]).style.display == "none" )		
			document.getElementById(arrayControls[i]).style.display = "";
	
	}
	return false;
}

function showTime(fechaMin, fechaMax, width, left, lin, df, lf, format, event){

	var multi =  (event.offsetX) / width;
	
	var dif = fechaMax.getTime() - fechaMin.getTime();
	var div = (multi * dif) + fechaMin.getTime();
	
	var dd = new Date();
	dd.setTime(parseInt(div));
	
	switch(parseInt(format)){
		case 0: lf.innerHTML =  " " + dd.toLocaleString();break;
		case 1: lf.innerHTML =  " " + dd.toLocaleDateString();break;
		case 2: lf.innerHTML =  " " + dd.toLocaleTimeString();break;
		default:lf.innerHTML =  " " + dd.toLocaleString();break;
	}
		
	lin.style.display="inline";
	lin.style.left= event.offsetX + left;
	df.style.display="inline";
	df.style.left = event.offsetX + left;

	
}

var iDrag = false;
var clienteX;
var clienteY;
var temp1;
var temp2;
var obj;

function initDrag(objDiv, event){

	iDrag=true;
	clienteX = event.clientX;
	clienteY= event.clientY;
	temp1 = objDiv.style.left;
	temp2 = objDiv.style.top;
	document.onmousemove = dragToolTip;
	document.onmouseup = documentDrop;
	objDiv.style.filter = 'alpha(opacity=20)';
	objDiv.style.cursor = 'move';
	obj = objDiv;

}

function dragToolTip(event){

	if(iDrag == true && obj != null){
		obj.style.left = parseInt(temp1) + window.event.clientX - clienteX;
		obj.style.top = parseInt(temp2) + window.event.clientY - clienteY;
	}
}

function documentDrop(){
	iDrag = false
	obj.style.filter = 'alpha(opacity=95)';
	obj.style.cursor = '';
}

function lockFirstColumn(cells, unitCells, oDiv){

	for(var i=0;i<cells.length; i++){
		document.getElementById(cells[i]).style.left = oDiv.scrollLeft -1 ;
		if(unitCells[i] != '')
		{
			document.getElementById(unitCells[i]).style.left = parseInt(oDiv.scrollLeft) - 1;	
		}
	}
}
